<?php
	require_once ("../../config.inc.php");
	require_once ("../../include/mysql.inc.php");
	require_once ("../../include/res.inc.php");
	
	$resDao = new Res();
	$pageIndex = mysql_escape_string($_POST["pageIndex"]);
	$tagId = mysql_escape_string($_POST["tagId"]);
	if (empty($tagId)) {
		$tagId = '';
	}
	
	$resList = $resDao->query($tagId, $pageIndex, ARTICLE_PAGE_SIZE);
	$resNum = $resDao->count($tagId);

	$dom = new DOMDocument("1.0","UTF-8");
	$ress = $dom->createElement("ress");
	$ress->setAttribute("total", $resNum);
	$ress->setAttribute("pageSize", ARTICLE_PAGE_SIZE);
	$ress->setAttribute("index", $pageIndex);
	foreach ($resList as $row) {
		$res = $dom->createElement("res");
		$res->setAttribute("id",$row[id]);
		
		$name = $dom->createElement("name", $row[name]);
		$path = $dom->createElement("path", $row[path]);
		$time = $dom->createElement("time", $row[time]);
		$type = $dom->createElement("type", $row[type]);
		$size = $dom->createElement("size", $row[size]);
		$top = $dom->createElement("top", $row[top]);
		$tagId = $dom->createElement("tagId", $row[tagId]);
		$tagName = $dom->createElement("tagName", $row[tagName]);
		$loadNum = $dom->createElement("num", $row[loadNum]);
	
		$res->appendChild($name);
		$res->appendChild($path);
		$res->appendChild($time);
		$res->appendChild($type);
		$res->appendChild($size);
		$res->appendChild($top);
		$res->appendChild($tagId);
		$res->appendChild($tagName);
		$res->appendChild($loadNum);
	
		$ress->appendChild($res);
	}
	
	$dom->appendChild($ress);
	header("Content-type:text/xml");
	$xmlfile = $dom->saveXML();
	file_put_contents("../../xml_data/ress.xml",$xmlfile);
	echo $xmlfile;
	
?>